package cn.sumpu.app.template.dao.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.sumpu.app.template.dao.AuxTestDao;
import cn.sumpu.app.template.domain.AuxTest;
import cn.sumpu.app.template.exception.AppBusinessException;

public class AuxTestDaoImpl extends SqlMapClientDaoSupport implements
		AuxTestDao {

	private static Logger logger = LoggerFactory
			.getLogger(AuxTestDaoImpl.class);

	@Override
	public void insert(AuxTest test) throws AppBusinessException {
		try {
			getSqlMapClientTemplate().insert("AuxTest.insert", test);
		} catch (DataAccessException e) {
			if (logger.isErrorEnabled()) {
				logger.error("Write database failure.", e);
			}
			throw new AppBusinessException("Write database failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AuxTest> get() throws AppBusinessException {
		try {
			return (List<AuxTest>) getSqlMapClientTemplate().queryForList(
					"AuxTest.selectAll");
		} catch (DataAccessException e) {
			if (logger.isErrorEnabled()) {
				logger.error("Read database failure.", e);
			}
			throw new AppBusinessException("Read database failure.", e);
		}
	}

}
